package info.motteke.util;

import java.util.ArrayList;
import java.util.List;

public final class LCM {

    private static final List<Integer> primes = new ArrayList<Integer>();

    static {

        primes.add(2);
        primes.add(3);
        primes.add(5);
        primes.add(7);
    }

    public static int lcm(int[] args) {
        if(args.length == 0){
            return -1;
        }

        if(args.length == 1){
            return args[0];
        }

        int[] calc = new int[args.length];
        System.arraycopy(args, 0, calc, 0, args.length);


        return lcm(calc, lcm(calc[0], calc[1]), 2);
    }

    private static int lcm(int[] args, int oldLcm, int index) {
        if(index == args.length){
            return oldLcm;
        }else {
            return lcm(args, lcm(oldLcm, args[index]), index + 1);
        }
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static int gcd(int a, int b) {
        return a < b ? _gcd(b, a) : _gcd(a, b);
    }

    private static int _gcd(int a, int b) {
        if(b == 0){
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(lcm(new int[]{250, 300, 450}));
    }

}
